import { CartItem } from "@/types/cart";
import { apiClient } from ".";
import { CartItemsResp, ApiResp } from "@/types/response";



export const cartService = {    
  getCartItems: async (pageNum: number, pageSize: number) => {
    const response = await apiClient.get<CartItemsResp>('/cart/items', { params: { pageNum, pageSize } });
    if (response.data.code === 0 && 'data' in response.data) {
      return response.data.data;
    }
    return { items: [], pageNum: 1, pageSize: 10, total: 0 };
  },

  removeCartItem: async (itemId: number) => {
    const response = await apiClient.post<ApiResp<number>>('/cart/remove-item', { itemId });
    if (response.data.code === 0 && 'data' in response.data) {
      return response.data.data;
    }
    return null;
  },          
  addToCart: async (skuId: number, quantity: number) => {   
    const response = await apiClient.post<ApiResp<number>>('/cart/add-item', { skuId, quantity });
    if (response.data.code === 0 && 'data' in response.data) {
      return response.data.data;
    }
    return null;
  } 
}


